--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  9_MarriedCouples_simCredit.log
  log type:  text
 opened on:  16 Apr 2018, 10:59:52

. ***************************************************************************;
. * GENERATE SIMULATED CREDIT ;
. ***************************************************************************;
. local beginTime "DateTime: $S_DATE $S_TIME";

. set more off ;

. set linesize 200 ;

. set mem 5g ;
set memory ignored.
    Memory no longer needs to be set in modern Statas; memory adjustments are performed on the fly automatically.

. set seed 123456789 ;

. cd "$dataDir" ;

. ***************************************************************************;
. * A LITTLE PROGRAM THAT TELLS US THE SIZE OF DATA IN MEMORY IN GIGS AND MEGS ;
. ***************************************************************************;
. program define sizer ;
  1.         qui des, short ;
  2.         di "OBSERVATIONS: " r(N) ;
  3.         di "DATA IN MEMORY (gbs): " round((r(width)+4)*r(N)/1024^3,.001) ;
  4.         di "DATA IN MEMORY (mbs): " round((r(width)+4)*r(N)/1024^3,.00001)*1000 ;
  5.         end ;

. ***************************************************************************;
. * SIMULATED MEASURES ;
. ***************************************************************************;
. program define simulator ;
  1.         args year suffix sample ;
  2.         di "BEGIN SIMULATOR - `year' `suffix' `sample'" ;
  3.         if "`sample'"=="uniform"{;
  4.                 * CREATE A UNIFORM DISTRIBUTION OF EARNINGS ;
.                 use cpi ;
  5.                 keep if year >= 1984 & year <= 2013 ;
  6.                 expand 100 ;
  7.                 sort year ;
  8.                 by year : gen pwages = 500 * (_n) ;
  9.                 by year : gen earn = 5 * (_n-1) ;
 10.                 expand 52 ;
 11.                 sort year pwages ;
 12.                 by year pwages : gen state = _n-1 ;
 13.                 expand 4 ;
 14.                 sort year pwages state ;
 15.                 by year pwages state : gen byte depx = _n-1 ;
 16.                 gen byte famsize = depx+1 ;
 17.                 gen byte depchild = depx ;
 18.                 gen byte children = depx ;
 19.                 gen byte mstat = 1 ;
 20.                 replace pwages = pwages * (cpi/232.957) ;
 21.                 replace earn = earn * (cpi/232.957) ;
 22.                 gen byte unearn = 0 ;
 23.                 gen byte wtsupp=1 ;
 24.                 };
 25.         else {;
 26.                 * SIMULATED INSTRUMENT USING THE CPS ;
.                 use cpi ;
 27.                 summ cpi if year == `year' ;
 28.                 local cpiSIV = r(mean) ;
 29.                 keep if year >= 1984 & year <= 2013 ;
 30.                 save cpiSpreadCPS, replace ;
 31.                 clear ;
 32.                 use if year == `year' using cpsBeforeTaxsim ;
 33.                 keep if `sample' ;
 34.                 count ;
 35.                 gen byte children = qualChild ;
 36.                 replace children = 3 if qualChild > 3 ;
 37.                 gen famsize = min(qualChild+2,5);
 38.                 gen earn = (pwages+swages)/12 ;
 39.                 gen unearn = max(otherprop+dividends+pensions+ui,0)/12 ;
 40.                 keep wtsuppW children state agex depx depchild mstat pwages swages gssi pensions ui otherprop transfers famsize earn unearn;
 41.                 rename state state_orig ;
 42.                 gen id = _n ;
 43.                 cross using cpiSpreadCPS ;
 44.                 sizer ;
 45.                 capture rm cpiSpreadCPS.dta ;
 46.                 foreach var of varlist pwages swages gssi pensions ui otherprop transfers earn unearn {;
 47.                         qui replace `var' = `var' * cpi/`cpiSIV' ;
 48.                         };
 49.                 qui expand 52 ;
 50.                 sort id year ;
 51.                 by id year : gen byte state = _n - 1 ;
 52.                 *drop id ;
.                 };
 53.         sizer ;
 54.         * RUN TAXSIM ;
.         capture rm msg.txt;
 55.         capture rm taxsim_out.dta;
 56.         ankurs_taxsim, full replace;
 57.         capture rm msg.txt;
 58.         capture rm taxsim_out.dta;
 59.         keep year state children v25 v39 v19 v22 v23 siitax v27 v40 cpi wtsuppW famsize earn unearn;
 60.         rename v25 fedEICSIV;
 61.         rename v39 stEICSIV ;
 62.         rename v19 fedRegTaxSIV ;
 63.         egen ctcSIV = rowtotal(v22 v23) ;
 64.         rename v27 amtSIV ;
 65.         gen stCredSIV = v40-stEICSIV ;
 66.         gen stRegTaxSIV = siitax+v40 ;
 67.         sort state year famsize ;
 68.         merge m:1 state year famsize using afdcparameterstemp2012 ;
 69.         drop if _merge == 2;
 70.         tab famsize _merge ;
 71.         tab year _merge ;
 72.         drop _merge ;
 73.         gen afdcSIV = afdccb*max(afdcmax-max(afdctax*(earn-afdcdis),0)-unearn,0) ;
 74.         replace afdcSIV = 0 if children == 0 ;
 75.         replace afdcSIV = afdcSIV*12 ;
 76.         keep year state children fedEICSIV fedRegTaxSIV ctcSIV amtSIV
>                 stEICSIV stRegTaxSIV stCredSIV cpi wtsupp afdcSIV ;
 77.         sort year state children ;
 78.         collapse (mean) fedEICSIV fedRegTaxSIV ctcSIV amtSIV stEICSIV stRegTaxSIV stCredSIV afdcSIV cpi [aw=wtsuppW],
>                 by(year state children) ;
 79.         foreach var of varlist fedEICSIV fedRegTaxSIV
>                         ctcSIV amtSIV stEICSIV stRegTaxSIV stCredSIV afdcSIV {;
 80.                 qui replace `var' = `var' * (232.957/cpi);
 81.                 rename `var' `var'_`suffix' ;
 82.                 };
 83.         drop cpi ;
 84.         sort year state children ;
 85.         save simulatedmeasures`suffix', replace ;
 86.         clear ;
 87.         end ;

. use afdcparameters ;

. expand 2 if year == 2011 ;
(468 observations created)

. sort state famsize year  ;

. by state famsize year: replace year = 2012 if year == 2011 & _n==2;
(468 real changes made)

. expand 2 if year == 2011 ;
(468 observations created)

. sort state famsize year  ;

. by state famsize year: replace year = 2013 if year == 2011 & _n==2;
(468 real changes made)

. duplicates report state famsize year ;

Duplicates in terms of state famsize year

--------------------------------------
   copies | observations       surplus
----------+---------------------------
        1 |        15444             0
--------------------------------------

. sort state year famsize ;

. save afdcparameterstemp2012, replace ;
(note: file afdcparameterstemp2012.dta not found)
file afdcparameterstemp2012.dta saved

. clear ;

. simulator "1982" "82cps" "statefip!=2&statefip!=15&incdisabW==0&incssW==0&incssiW==0&ageW>=24&ageW<=48" ;
BEGIN SIMULATOR - 1982 82cps statefip!=2&statefip!=15&incdisabW==0&incssW==0&incssiW==0&ageW>=24&ageW<=48

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
         cpi |          1        96.5           .       96.5       96.5
(71 observations deleted)
(note: file cpiSpreadCPS.dta not found)
file cpiSpreadCPS.dta saved
(16,437 observations deleted)
  19,617
(1,299 real changes made)
OBSERVATIONS: 588510
DATA IN MEMORY (gbs): .035
DATA IN MEMORY (mbs): 35.08
OBSERVATIONS: 30602520
DATA IN MEMORY (gbs): 1.853
DATA IN MEMORY (mbs): 1852.55
begin taxsim9.ado on 16 Apr 2018 (version 9.0)
TAXSIM results will be merged to original file
TAXSIM results will be saved in taxsim_out.dta
Full Intermediate Calculations Requested
Marginal rate with respect to primary earner
Variable dividends is not in the dataset.  Generating dividends = 0 
Variable rentpaid is not in the dataset.  Generating rentpaid = 0 
Variable proptax is not in the dataset.  Generating proptax = 0 
Variable otheritem is not in the dataset.  Generating otheritem = 0 
Variable childcare is not in the dataset.  Generating childcare = 0 
Variable mortgage is not in the dataset.  Generating mortgage = 0 
Variable stcg is not in the dataset.  Generating stcg = 0 
Variable ltcg is not in the dataset.  Generating ltcg = 0 
30602520 records out of 30602520 are left for taxsim to process
 
TAXSIM results are being merged with workspace by taxsimid
variable taxsimid does not uniquely identify observations in the master data
(note: variable year was int, now float to accommodate using data's values)
(note: variable state was byte, now float to accommodate using data's values)
 
(22,549,978 missing values generated)
(22,549,978 missing values generated)

    Result                           # of obs.
    -----------------------------------------
    not matched                         9,205
        from master                         1  (_merge==1)
        from using                      9,204  (_merge==2)

    matched                        30,602,520  (_merge==3)
    -----------------------------------------
(9,204 observations deleted)

           |   _merge
   famsize | matched ( |     Total
-----------+-----------+----------
         2 | 6,915,480 | 6,915,480 
         3 | 7,725,120 | 7,725,120 
         4 | 9,729,720 | 9,729,720 
         5 | 6,232,200 | 6,232,200 
-----------+-----------+----------
     Total |30,602,520 |30,602,520 


           |        _merge
      year | master on  matched ( |     Total
-----------+----------------------+----------
       .53 |         1          0 |         1 
      1984 |         0  1,020,084 | 1,020,084 
      1985 |         0  1,020,084 | 1,020,084 
      1986 |         0  1,020,084 | 1,020,084 
      1987 |         0  1,020,084 | 1,020,084 
      1988 |         0  1,020,084 | 1,020,084 
      1989 |         0  1,020,084 | 1,020,084 
      1990 |         0  1,020,084 | 1,020,084 
      1991 |         0  1,020,084 | 1,020,084 
      1992 |         0  1,020,084 | 1,020,084 
      1993 |         0  1,020,084 | 1,020,084 
      1994 |         0  1,020,084 | 1,020,084 
      1995 |         0  1,020,084 | 1,020,084 
      1996 |         0  1,020,084 | 1,020,084 
      1997 |         0  1,020,084 | 1,020,084 
      1998 |         0  1,020,084 | 1,020,084 
      1999 |         0  1,020,084 | 1,020,084 
      2000 |         0  1,020,084 | 1,020,084 
      2001 |         0  1,020,084 | 1,020,084 
      2002 |         0  1,020,084 | 1,020,084 
      2003 |         0  1,020,084 | 1,020,084 
      2004 |         0  1,020,084 | 1,020,084 
      2005 |         0  1,020,084 | 1,020,084 
      2006 |         0  1,020,084 | 1,020,084 
      2007 |         0  1,020,084 | 1,020,084 
      2008 |         0  1,020,084 | 1,020,084 
      2009 |         0  1,020,084 | 1,020,084 
      2010 |         0  1,020,084 | 1,020,084 
      2011 |         0  1,020,084 | 1,020,084 
      2012 |         0  1,020,084 | 1,020,084 
      2013 |         0  1,020,084 | 1,020,084 
-----------+----------------------+----------
     Total |         1 30,602,520 |30,602,521 

(1 missing value generated)
(334,862 real changes made)
(1,732,901 real changes made)
(note: file simulatedmeasures82cps.dta not found)
file simulatedmeasures82cps.dta saved

. use simulatedmeasures82cps ;

. rm simulatedmeasures82cps.dta ;

. save simulatedmeasures, replace ;
file simulatedmeasures.dta saved

. clear ;

. disp "`beginTime'" ;
DateTime: 16 Apr 2018 10:59:52

. disp "DateTime: $S_DATE $S_TIME";
DateTime: 16 Apr 2018 11:56:31

. */
> *;
. disp "`beginTime'" ;
DateTime: 16 Apr 2018 10:59:52

. disp "DateTime: $S_DATE $S_TIME";
DateTime: 16 Apr 2018 11:56:31

. log close ;
      name:  <unnamed>
       log:  9_MarriedCouples_simCredit.log
  log type:  text
 closed on:  16 Apr 2018, 11:56:31
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
